package com.ams.protocol.rtmp.net;

import java.io.File;
import java.util.HashMap;

import com.ams.media.MimeTypes;
import com.ams.protocol.Context;

public final class NetContext extends Context {
    private final String contextRoot;

    public NetContext(String root) {
        contextRoot = root;
        attributes = new HashMap<String, String>();
    }

    public String getPublishName(String app, String streamName) {
        return app + "/" + streamName;
    }

    public String getRealPath(String app, String path, String type) {
        if ("unkown/unkown".equals(MimeTypes.getMimeType(path))) {
            if (type == null || "".equals(type)) {
                path += ".flv";
            } else {
                path += "." + type;
            }
        }
        if (app != null && app.length() > 0) {
            return new File(contextRoot, app + File.separatorChar + path)
                    .getAbsolutePath();
        }
        return new File(contextRoot, path).getAbsolutePath();
    }

}
